package com.wyyc.common.user.controller;

import com.alibaba.fastjson.JSON;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import com.wyyc.common.user.service.UserService;
import com.wyyc.entity.ResJson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Hwei~ on 2017/6/6.
 */
@Controller
@RequestMapping("request/userinfo/")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/headFile", method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String upPic(MultipartFile file,HttpServletRequest request,Integer uid) throws Exception {
        if (file!=null&&uid!=null){
            ResJson resJson = userService.updHeadUrl(file, request, uid);
            return JSON.toJSONString(resJson);
        }
        return "";
    }

    @RequestMapping(value = "/updGender",method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String updGender(Integer uid,Integer gender){
        if (uid!=null&&gender!=null){
            ResJson resJson = userService.updGender(uid, gender);
            return JSON.toJSONString(resJson);
        }
        return "";
    }
}
